"""Configuration and data classes for vLLM Benchmark."""

import os
from dataclasses import dataclass, field
from typing import List, Dict, Optional

# Set HuggingFace mirror for China
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"


# ==================== Configuration Data Classes ====================

@dataclass
class VLLMConfig:
    """vLLM service configuration."""
    base_url: str = "http://localhost:8000/v1"
    model: str = "Qwen/Qwen2.5-3B-Instruct"
    timeout: int = 120


@dataclass
class OllamaConfig:
    """Ollama service configuration."""
    base_url: str = "http://localhost:11434"
    model: str = "qwen3:4b-instruct"
    timeout: int = 120


@dataclass
class TestConfig:
    """Test execution configuration."""
    concurrent_levels: List[int] = field(default_factory=lambda: [1, 5, 10, 20, 30])
    max_tokens: int = 512
    temperature: float = 0.7
    timeout: int = 120


# ==================== Result Data Classes ====================

@dataclass
class RequestResult:
    """Result from a single inference request."""
    backend: str
    question: str
    latency: float  # seconds
    tokens: int
    success: bool
    error: str = ""
    response: str = ""
    timestamp: float = 0.0


@dataclass
class BenchmarkResult:
    """Aggregated benchmark results."""
    backend: str
    concurrent_level: int
    total_requests: int
    successful_requests: int
    failed_requests: int
    total_time: float  # seconds
    throughput: float  # requests/sec
    avg_latency: float  # seconds
    p50_latency: float
    p95_latency: float
    p99_latency: float
    tokens_per_second: float


# ==================== Test Data ====================

# Hydrology domain questions for benchmarking
HYDROLOGY_QUESTIONS: List[str] = [
    "什么是流域汇流时间？如何计算？",
    "解释新安江模型的三层蒸散发结构原理",
    "洪水预报中的产流计算方法有哪些？各有什么特点？",
    "什么是Nash单位线？它的参数n和k的物理意义是什么？",
    "降雨径流关系受哪些因素影响？",
    "如何使用时段单位线法进行洪水演算？",
    "水文模型率定的目标函数有哪些？如何选择？",
    "分布式水文模型和集总式水文模型的主要区别是什么？",
    "蒸散发计算的Penman-Monteith公式的原理是什么？",
    "地下水与地表水的相互作用如何在水文模型中表达？",
    "融雪径流模拟的关键参数有哪些？",
    "水文模型的不确定性来源有哪些？如何量化？",
    "什么是土壤含水量张力水容量？它在产流计算中的作用？",
    "河道洪水演进的马斯京根法的基本原理是什么？",
    "水文预报的精度评价指标有哪些？如何计算纳什效率系数？",
]


# ==================== Default Instances ====================

# Default configuration instances
DEFAULT_VLLM_CONFIG = VLLMConfig()
DEFAULT_OLLAMA_CONFIG = OllamaConfig()
DEFAULT_TEST_CONFIG = TestConfig()

